*===============================================================================
* Do-file creates "Figure 2: Administrative Dataset: Trends in Violence Exposure & M-Paisa Transactions"
*===============================================================================
clear 
set more off

cd "~/Dropbox/VFD/REStat_Native_Files/Stata_Files"
local output "~/Dropbox/VFD/REStat_Native_Files/Stata_Files/Output"


use "monthpanel_analysis.dta", clear
keep if salary==1
gen trimmedobs=0
sum balance, d
replace trimmedobs =1 if (balance <=r(p99) & balance>=r(p1))
replace trimmedobs =. if balance ==.
bys identityid: egen trimmed_extusers = min(trimmedobs)
keep if trimmed_extusers==1

* Collapse at year-month level
bys identityid: egen num_mo=count(ym)
drop if num_mo==1 //to ensure it is the same as estimation sample in Table 1
collapse (mean) num* balance violence* df* idf* ied_5km ied_10km d_*, by(ym)

label var balance "Balance"
label var numtxns "Transactions"
label var numwithdrawal "Withdrawals"
label var numdeposit "Deposits"
label var numtransferdebit "Send Money"
label var d_violence_10km "All violent events"
label var d_df_10km "Direct Fire"
label var d_idf_10km "Indirect Fire"
label var d_ied_10km "IED"
label var violence_10km "All violent events"
label var df_10km "Direct Fire"
label var idf_10km "Indirect Fire"
label var ied_10km "IED"




* Figure 2a: Trends in Violence Exposure (Dec 2010 - April 2012)
gr tw ///
(connected d_violence_10km ym)  /// 
(connected d_df_10km ym)  /// 
(connected d_ied_10km ym) ///
(connected d_idf_10km ym),  ///
scheme(plotplain) xlabel(611(2)627,nogrid) ///
ytitle("Incidents within 10km radius (Share)") xtitle("") ///
legend(cols(4) pos(6)) ylabel(0(0.2)1)
gr export "`output'/fig_violence.png", replace


* Figure 2b: Trends in M-Paisa Transactions (Dec 2010 - April 2012)
gr tw ///
(connected balance ym, ylabel(0(1000)5000)) ///
(connected numtxns ym, yaxis(2))  /// 
(connected numwithdrawal ym, yaxis(2))  ///
(connected numdeposit ym, yaxis(2))  ///
(connected numtransferdebit ym, yaxis(2)), ///
scheme(plotplain) xlabel(611(2)627,nogrid) ///
ytitle("Mean") xtitle("") ///
legend(cols(5) pos(5))
gr export "`output'/fig_mpaisa.png", replace





